package sigepa;

import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import pe.edu.pucp.Modelo.Permiso;
import pe.edu.pucp.Modelo.Usuario;
import pe.edu.pucp.Util.Constante;
import pe.edu.pucp.Util.ValHelper;

public class MainMenuGUI extends javax.swing.JFrame {
    /**
     * Creates new form testPerfilGUI
     */
    public MainMenuGUI() {
        initComponents();
        setLocationRelativeTo(null);     
    }  
        
    public void llenarPanelInfo(Usuario usr){
        lblNombre.setText(usr.getNombre()+" "+usr.getAppaterno());
        lblCiudad.setText(usr.getAeropuerto().getCiudad().getDescripcion());
    }   
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        sesionPanel = new javax.swing.JPanel();
        btnSalir = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        lblNombre = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblCiudad = new javax.swing.JLabel();
        btnSesion = new javax.swing.JButton();
        btnCambia = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        test = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jmSeguridad = new javax.swing.JMenu();
        jmPerfil = new javax.swing.JMenuItem();
        jmUsuario = new javax.swing.JMenuItem();
        jmConfiguracion = new javax.swing.JMenuItem();
        jmRepAuditoria = new javax.swing.JMenuItem();
        jmAdministracion = new javax.swing.JMenu();
        jmAeropuerto = new javax.swing.JMenuItem();
        jmCargaVuelo = new javax.swing.JMenuItem();
        jmCargaMasiva = new javax.swing.JMenuItem();
        jmEnvios = new javax.swing.JMenu();
        jmVuelo = new javax.swing.JMenuItem();
        jmCliente = new javax.swing.JMenuItem();
        jmAlmacen = new javax.swing.JMenuItem();
        jmRepEnvio = new javax.swing.JMenuItem();
        jmSimulacion = new javax.swing.JMenu();
        jmSimulador = new javax.swing.JMenuItem();
        jmReportes = new javax.swing.JMenu();
        jmRepKardex = new javax.swing.JMenuItem();
        jmRepAlmacen = new javax.swing.JMenuItem();
        jmRepCancelacion = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SIGEPA - Inicio");

        sesionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        sesionPanel.setMaximumSize(new java.awt.Dimension(165, 700));
        sesionPanel.setMinimumSize(new java.awt.Dimension(165, 700));
        sesionPanel.setPreferredSize(new java.awt.Dimension(165, 700));

        btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/shut_down.png"))); // NOI18N
        btnSalir.setToolTipText("Salir");

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel1.setText("Usuario : ");

        lblNombre.setText("-------");

        jLabel3.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel3.setText("Ciudad: ");

        lblCiudad.setText("-------");

        btnSesion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/user.png"))); // NOI18N
        btnSesion.setToolTipText("Cerrar Sesion");

        btnCambia.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/key.png"))); // NOI18N
        btnCambia.setToolTipText("Cambiar Contraseña");

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/img/logoredex.png"))); // NOI18N

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/img/logosmall.png"))); // NOI18N

        javax.swing.GroupLayout sesionPanelLayout = new javax.swing.GroupLayout(sesionPanel);
        sesionPanel.setLayout(sesionPanelLayout);
        sesionPanelLayout.setHorizontalGroup(
            sesionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(sesionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(sesionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(sesionPanelLayout.createSequentialGroup()
                        .addGroup(sesionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblCiudad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sesionPanelLayout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(btnCambia, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnSesion, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(sesionPanelLayout.createSequentialGroup()
                        .addGroup(sesionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addGap(0, 0, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sesionPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(sesionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addGap(32, 32, 32))
        );
        sesionPanelLayout.setVerticalGroup(
            sesionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, sesionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblNombre)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCiudad)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 352, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(32, 32, 32)
                .addGroup(sesionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSesion, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCambia, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        test.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        test.setMaximumSize(new java.awt.Dimension(764, 700));
        test.setMinimumSize(new java.awt.Dimension(764, 700));
        test.setOpaque(false);
        test.setPreferredSize(new java.awt.Dimension(764, 700));

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recurso/img/logobig.png"))); // NOI18N

        javax.swing.GroupLayout testLayout = new javax.swing.GroupLayout(test);
        test.setLayout(testLayout);
        testLayout.setHorizontalGroup(
            testLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(testLayout.createSequentialGroup()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 760, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        testLayout.setVerticalGroup(
            testLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(testLayout.createSequentialGroup()
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 696, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jmSeguridad.setText("Seguridad");

        jmPerfil.setText("Perfiles");
        jmSeguridad.add(jmPerfil);

        jmUsuario.setText("Usuarios");
        jmSeguridad.add(jmUsuario);

        jmConfiguracion.setText("Configuración");
        jmSeguridad.add(jmConfiguracion);

        jmRepAuditoria.setText("Auditoria");
        jmSeguridad.add(jmRepAuditoria);

        jMenuBar1.add(jmSeguridad);

        jmAdministracion.setText("Administración");

        jmAeropuerto.setText("Aeropuertos");
        jmAdministracion.add(jmAeropuerto);

        jmCargaVuelo.setText("Carga Vuelos");
        jmAdministracion.add(jmCargaVuelo);

        jmCargaMasiva.setText("Carga Masiva");
        jmAdministracion.add(jmCargaMasiva);

        jMenuBar1.add(jmAdministracion);

        jmEnvios.setText("Envíos");

        jmVuelo.setText("Vuelos");
        jmEnvios.add(jmVuelo);

        jmCliente.setText("Clientes");
        jmEnvios.add(jmCliente);

        jmAlmacen.setText("Almacenes");
        jmEnvios.add(jmAlmacen);

        jmRepEnvio.setText("Reporte");
        jmEnvios.add(jmRepEnvio);

        jMenuBar1.add(jmEnvios);

        jmSimulacion.setText("Simulación");

        jmSimulador.setText("Simulador");
        jmSimulacion.add(jmSimulador);

        jMenuBar1.add(jmSimulacion);

        jmReportes.setText("Reportes");

        jmRepKardex.setText("Kardex");
        jmReportes.add(jmRepKardex);

        jmRepAlmacen.setText("Almacen");
        jmReportes.add(jmRepAlmacen);

        jmRepCancelacion.setText("Cancelacion");
        jmReportes.add(jmRepCancelacion);

        jMenuBar1.add(jmReportes);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(test, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(sesionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(sesionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(test, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem14ActionPerformed
    }//GEN-LAST:event_jMenuItem14ActionPerformed
     
    public void mostrarPermisos(ArrayList<Permiso> list){
        if (!list.isEmpty()){                                
            jmPerfil.setEnabled(buscarPermiso(list,Constante.P_SEG_PERFIL)==1);
            jmUsuario.setEnabled(buscarPermiso(list,Constante.P_SEG_USUARIO)==1);
            jmConfiguracion.setEnabled(buscarPermiso(list,Constante.P_SEG_CONFIGURACION)==1);
            jmRepAuditoria.setEnabled(buscarPermiso(list,Constante.P_SEG_REPORTE)==1);

            jmAeropuerto.setEnabled(buscarPermiso(list,Constante.P_ADM_AEROPUERTO)==1);
            jmCargaVuelo.setEnabled(buscarPermiso(list,Constante.P_ADM_CARGAVUELO)==1);
            jmCargaMasiva.setEnabled(buscarPermiso(list,Constante.P_ADM_CARGAMASIVA)==1);

            jmVuelo.setEnabled(buscarPermiso(list,Constante.P_ENV_VUELO)==1);
            jmCliente.setEnabled(buscarPermiso(list,Constante.P_ENV_CLIENTE)==1);
            jmAlmacen.setEnabled(buscarPermiso(list,Constante.P_ENV_ALMACEN)==1);
            jmRepEnvio.setEnabled(buscarPermiso(list,Constante.P_ENV_REPORTE)==1);

            jmSimulador.setEnabled(buscarPermiso(list,Constante.P_SIM_SIMULACION)==1);

            jmRepKardex.setEnabled(buscarPermiso(list,Constante.P_REP_KARDEX)==1);
            jmRepCancelacion.setEnabled(buscarPermiso(list,Constante.P_REP_CANCELACION)==1);
            jmRepAlmacen.setEnabled(buscarPermiso(list,Constante.P_REP_ALMACEN)==1);                            
        }
    }

    public int buscarPermiso(ArrayList<Permiso> list, int idel){
        int per=-1;
        for (Permiso c : list){ if (c.getElemento().getIdelemento()==idel) per =c.getPermiso(); }
        return per;
    }   
    
    public void addMostrarCargarVuelos(ActionListener listener) { jmCargaVuelo.addActionListener(listener); }
    
    public void addConfiguracion(ActionListener listener) { this.jmConfiguracion.addActionListener(listener); }
        
    public void addBuscarUsuario(ActionListener listener) { this.jmUsuario.addActionListener(listener); }        
    
    public void addMostrarSimulacion(ActionListener listener) { this.jmSimulador.addActionListener(listener); }
    
    public void addMostrarReporteKardex(ActionListener listener) { this.jmRepKardex.addActionListener(listener); }
    
    public void addMostrarReporteAlmacen(ActionListener listener) { this.jmRepAlmacen.addActionListener(listener); }
    
    public void addMostrarReporteAuditoria(ActionListener listener) { this.jmRepAuditoria.addActionListener(listener); }
    
    public void addMostrarReporteCancelacion(ActionListener listener) { this.jmRepCancelacion.addActionListener(listener); }
    
    public void addMostrarReporteEnvios(ActionListener listener) { this.jmRepEnvio.addActionListener(listener); }        
    
    public void addMostrarVuelos(ActionListener listener) { this.jmVuelo.addActionListener(listener); }
        
    public void addBuscarPerfil(ActionListener listener) { this.jmPerfil.addActionListener(listener); }  
         
    public void addBuscarCliente(ActionListener listener) { this.jmCliente.addActionListener(listener); }                                      
     
    public void addBuscarAlmacen(ActionListener listener) { this.jmAlmacen.addActionListener(listener); } 
         
    public void addBuscarAeropuerto(ActionListener listener) { this.jmAeropuerto.addActionListener(listener); } 
          
    public void addDatosMasivos(ActionListener listener) { this.jmCargaMasiva.addActionListener(listener); }  
         
    public void addSalir(ActionListener listener){ this.btnSalir.addActionListener(listener); }
    
    public void addSesion(ActionListener listener){ this.btnSesion.addActionListener(listener); }
    
    public void addVentana(WindowListener listener){ this.addWindowListener(listener); }
    
    public void addCambiar(ActionListener listener){ this.btnCambia.addActionListener(listener); }
    
    public void setCurrentPanel(Component p){
        this.getContentPane().removeAll();
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(p, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(sesionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(sesionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(p, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }
    
    
    
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCambia;
    private javax.swing.JButton btnSalir;
    private javax.swing.JButton btnSesion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenu jmAdministracion;
    private javax.swing.JMenuItem jmAeropuerto;
    private javax.swing.JMenuItem jmAlmacen;
    private javax.swing.JMenuItem jmCargaMasiva;
    private javax.swing.JMenuItem jmCargaVuelo;
    private javax.swing.JMenuItem jmCliente;
    private javax.swing.JMenuItem jmConfiguracion;
    private javax.swing.JMenu jmEnvios;
    private javax.swing.JMenuItem jmPerfil;
    private javax.swing.JMenuItem jmRepAlmacen;
    private javax.swing.JMenuItem jmRepAuditoria;
    private javax.swing.JMenuItem jmRepCancelacion;
    private javax.swing.JMenuItem jmRepEnvio;
    private javax.swing.JMenuItem jmRepKardex;
    private javax.swing.JMenu jmReportes;
    private javax.swing.JMenu jmSeguridad;
    private javax.swing.JMenu jmSimulacion;
    private javax.swing.JMenuItem jmSimulador;
    private javax.swing.JMenuItem jmUsuario;
    private javax.swing.JMenuItem jmVuelo;
    private javax.swing.JLabel lblCiudad;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JPanel sesionPanel;
    private javax.swing.JPanel test;
    // End of variables declaration//GEN-END:variables
}
